package com.dogdays;

import com.dogdays.account.AccountVerticle;
import com.dogdays.account.RestAccountAPIVerticle;
import io.vertx.core.Vertx;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;

import javax.annotation.PostConstruct;

@SpringBootApplication
public class Application {

    private Vertx vertx;

    @Autowired
    private AccountVerticle accountVerticle;

    @Autowired
    private RestAccountAPIVerticle restAccountAPIVerticle;

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }

    /**
     * A singleton instance of {@link Vertx} which is used throughout the application
     *
     * @return An instance of {@link Vertx}
     */
    @Bean
    public Vertx getVertxInstance() {
        if (this.vertx == null) {
            this.vertx = Vertx.vertx();
        }
        return this.vertx;
    }

    @PostConstruct
    public void deployVerticle() {
        this.vertx.deployVerticle(accountVerticle);
        this.vertx.deployVerticle(restAccountAPIVerticle);
    }

}
